<!-- 在线报修 -->
<template>
  <div>
    <at-menu mode="horizontal" active-name="1">
      <at-menu-item name="1">
        <i class="icon icon-chevron-left" @click="mback"></i>在线报修
      </at-menu-item>
    </at-menu>
    <el-form
      width="50%"
      :model="formLabelAlign"
      :label-position="labelposition"
      style="margin-top:30px"
      label-width="100px"
      ref="ruleForm"
    >
      <el-form-item label="时间">
        <el-input v-model="formLabelAlign.date" disabled></el-input>
      </el-form-item>
      <el-form-item label="需维修器材">
        <el-input v-model="formLabelAlign.name"></el-input>
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="formLabelAlign.des"></el-input>
      </el-form-item>
      <el-form-item label="图片">
        <el-upload
          action="#"
          list-type="picture-card"
          :auto-upload="false"
          :on-success="handleAvatarSuccess"
        >
          <i slot="default" class="el-icon-plus"></i>
          <div slot="file" slot-scope="{file}">
            <img class="el-upload-list__item-thumbnail" :src="file.url" alt />
            <span class="el-upload-list__item-actions">
              <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                <i class="el-icon-zoom-in"></i>
              </span>
              <span
                v-if="!disabled"
                class="el-upload-list__item-delete"
                @click="handleDownload(file)"
              >
                <i class="el-icon-download"></i>
              </span>
            </span>
          </div>
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt />
    </el-dialog>
  </div>
</template>

<script>
import { back, getNowFormatDate } from "../../assets/js/common";
import { mapState, mapMutations } from "vuex";
export default {
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      formLabelAlign: {
        date: "",
        name: "",
        des: "",
        imgurl: ""
      },
      labelposition: "left",
      imageUrl: ""
    };
  },

  components: {},

  computed: { ...mapState(["repairlist"]) },

  created() {
    this.formLabelAlign.date = getNowFormatDate();
  },

  methods: {
    ...mapMutations(["changeRepairlist"]),
    handleAvatarSuccess(res, file) {
      console.log(file);
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.formLabelAlign.imgurl = this.dialogImageUrl;
          this.changeRepairlist(this.formLabelAlign);
          console.log(this.repairlist);
          this.$message({
            message: "提交成功",
            type: "success"
          });
          this.$router.push({
            path: "/repair"
          });
        } else {
          console.log("提交失败");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.formLabelAlign = {
        date: getNowFormatDate(),
        name: "",
        des: "",
        imgurl: ""
      };
    },
    mback() {
      back();
    },
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      //this.dialogImageUrl = file.url;
      this.dialogImageUrl = URL.createObjectURL(file.raw);
      console.log(file);
      this.dialogVisible = true;
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    handleDownload(file) {
      console.log(file);
    }
  }
};
</script>
<style>
.el-form-item {
  display: flex;
}
.el-form-item__content {
  margin-left: 0 !important;
}
</style>